package com.zh.blog.strategy.context;

import com.zh.blog.dto.UserInfoDto;
import com.zh.blog.enums.LoginTypeEnum;
import com.zh.blog.strategy.SocialLoginStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 第三方登录策略上下文
 * @author ZhengHao
 * Created At 2022/8/25.
 **/
@Service
public class SocialLoginStrategyContext {
    @Autowired
    private Map<String, SocialLoginStrategy> socialLoginStrategyMap;

    public UserInfoDto executeLoginStrategy(String data, LoginTypeEnum loginTypeEnum) {
        return socialLoginStrategyMap.get(loginTypeEnum.getStrategy()).login(data);
    }
}